<?php
// Date manipulation --------------------

function mydate($date) 
{
 return strftime("%d-%m-%Y", strtotime($date)); // input:  2009-12-01 19:31:38   --> output 01-12-2009
}
function myfull_date($date) 
{
 return strftime("%d-%m-%Y %H:%M", strtotime($date)); // output 01-12-2009 19:31
 //return strftime("%A, %d-%m-%Y %I:%M %p", strtotime($date)); // output Tuesday, 01-12-2009 9:31 AM
}
function my_int_date($date) 
{
 return date("d-m-Y",$date); // input:  548751255  --> output 01-12-2009
}
function myfull_int_date($date) 
{
 // Disable timezone in php.ini then set in code http://www.php.net/manual/en/timezones.europe.php
 //date_default_timezone_set('Europe/Copenhagen'); Danish
 //date_default_timezone_set('Asia/Ho_Chi_Minh');
 return date("d-m-Y H:i",$date); // output 01-12-2009 19:31
 //return date("l d-m-Y h:i a",$date); // output Sun 16-03-1975 08:19 am 
}

// End date -----------------------------

 function mb_substrws( $text, $link='', $len=60 ) {
          if( (mb_strlen($text) > $len) ) 
		  {
     
              $whitespaceposition = mb_strpos($text," ",$len)-1;
     
              if( $whitespaceposition > 0 ) 
			  {
                  $chars = count_chars(mb_substr($text, 0, ($whitespaceposition+1)), 1);
                  if ($chars[ord('<')] > $chars[ord('>')])
                      $whitespaceposition = mb_strpos($text,">",$whitespaceposition)-1;
                  $text = mb_substr($text, 0, ($whitespaceposition+1)).'&nbsp;<span class="more"><a href="'.$link.'">' . JText::_('READ_MORE') . '</a></span>';
              }
     
              // close unclosed html tags
              if( preg_match_all("|<([a-zA-Z]+)|",$text,$aBuffer) ) 
			  {
     
                  if( !empty($aBuffer[1]) ) 
				  {
     
                      preg_match_all("|</([a-zA-Z]+)>|",$text,$aBuffer2);
     
                      if( count($aBuffer[1]) != count($aBuffer2[1]) ) 
					  {
     
                          foreach( $aBuffer[1] as $index => $tag ) 
						  {
     
                              if( empty($aBuffer2[1][$index]) || $aBuffer2[1][$index] != $tag)
                                  $text .= '</'.$tag.'>';
                          }
                      }
                  }
              }
          }
          return $text;
      }